﻿using System;
using System.Windows;
using System.Diagnostics;
using Infrastructure.Utility;

namespace MainClientSystem
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup( StartupEventArgs e )
        {
            base.OnStartup( e );

            Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            LogonScreen logon = new LogonScreen();
            bool? res = logon.ShowDialog();
            Application.Current.MainWindow = null;
            Application.Current.ShutdownMode = ShutdownMode.OnMainWindowClose;

            if ( res.HasValue && res.Value && LogonScreen.bIsLogonSuccess )
            {
                // The boostrapper will create the Shell instance, so the App.xaml does not have a StartupUri.
                TheBootstrapper bootstrapper = new TheBootstrapper();
                bootstrapper.Run();
            }
            else
            {
                //MessageBox.Show(
                //    "Application is exiting due to invalid credentials",
                //    "Application Exit",
                //    MessageBoxButton.OK,
                //    MessageBoxImage.Error );
                Application.Current.Shutdown( 1 );
            }
        }

        protected override void OnExit( ExitEventArgs e )
        {
            Debug.WriteLine( "LOGGER OUTPUT" );
            Debug.WriteLine( XmlLogger.ReadLogFile() );
        }
    }
}
